package com.cz.run.utils;

import com.alibaba.fastjson.JSON;
import com.cz.run.beans.base.ReturnDTO;
import com.cz.run.enums.SystemCodeEnum;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description: TODO()
 * @auther:CAIYJ
 * @Date:2018/5/25 23:11
 */
public class HttpResponseUtil {
    public static void noUser(HttpServletResponse response) throws IOException {
        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");
        response.getWriter().write(JSON.toJSONString(
                ReturnDTO.fail(SystemCodeEnum.userpwd_not_exist)));
        response.getWriter().flush();
        response.getWriter().close();
    }

    public static void noAuth(HttpServletResponse response) throws IOException {
        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");
        response.getWriter().write(JSON.toJSONString(
                ReturnDTO.fail(SystemCodeEnum.http_status_forbidden)));
        response.getWriter().flush();
        response.getWriter().close();
    }

    public static void noLogin(HttpServletResponse response)
            throws IOException {
        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");
        response.getWriter().write(
                JSON.toJSONString(ReturnDTO.fail(SystemCodeEnum.no_login)));
        response.getWriter().flush();
        response.getWriter().close();
    }
}
